/**
 * @date: 2025/3/22
 * @fileName: app
 * @Description: app
 */
import { acceptHMRUpdate, defineStore } from 'pinia';
import type { SupportedLanguagesType } from '@/locales';

interface AppState {
	/**
	 * 默认语言
	 */
	locale: SupportedLanguagesType;
}

export const useAppStore = defineStore('app', {
	state: (): AppState => ({
		locale: 'zh-CN',
	}),
	actions: {
		/**
		 * 设置语言
		 * @param locale
		 */
		setLocale(locale: SupportedLanguagesType) {
			this.locale = locale;
		},
	},
	persist: {
		pick: ['locale'],
	},
});

// 解决热更新问题
const hot = import.meta.hot;
if (hot) {
	hot.accept(acceptHMRUpdate(useAppStore, hot));
}
